<?php
/**
 * Created by PhpStorm.
 * User: wangkk
 * Date: 2019-03-20 17:41
 * Description: {创建卡券货架}
 */

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha;

$this->title = '创建卡券货架';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-contact">
    <h1><?= Html::encode($this->title) ?></h1>
    <div class="row">
        <div class="col-lg-5">
            <?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
            <?= $form->field($model, 'cardpage_name')->textInput(['placeholder'=>'自定义货架名称，非微信字段']) ?>
            <?= $form->field($model, 'banner')->textInput(['placeholder'=>'页面banner图片地址，必须是上传到微信服务器图片']) ?>
            <?= $form->field($model, 'page_title')->textInput(['placeholder'=>'页面title信息，不超过9个汉字','maxlength'=>9]) ?>
            <?= $form->field($model, 'can_share')->dropDownList(['1'=>'允许分享', '0'=>'不允许分享']) ?>
            <?= $form->field($model, 'scene')->dropDownList($scenelist) ?>
            <div class="form-group field-cardpageform">
                <label class="control-label">货架卡券列表（最多五个）</label>
                <button type="button" id="add-button" class="btn btn-primary" onclick="addCard()">添加</button>
            </div>
            <!--<?= $form->field($model, 'card_id[]')->textInput(['placeholder'=>'卡券批次card_id'])->label(false) ?>-->
            <!--<?= $form->field($model, 'thumb_url[]')->textInput(['placeholder'=>'卡券缩略图地址，必须是上传到微信服务器图片'])->label(false) ?>-->
            <div class="form-group field-cardpageform-card_id required ">
                <label class="control-label">卡券批次card_id</label>
                <input type="text" id="cardpageform-card_id" class="form-control" name="CardPageForm[card_id][]" placeholder="卡券批次card_id" aria-invalid="true">
                <p class="help-block help-block-error"></p>
            </div>
            <div class="form-group field-cardpageform-thumb_url required">
                <label class="control-label">卡券缩略图地址</label>
                <input type="text" id="cardpageform-thumb_url" class="form-control" name="CardPageForm[thumb_url][]" placeholder="卡券缩略图地址，必须是上传到微信服务器图片">
                <p class="help-block help-block-error"></p>
            </div>
            <div class="form-group">
                <?= Html::submitButton('提交', ['class' => 'btn btn-primary','id'=>'submit_form', 'name' => 'contact-button']) ?>
            </div>
            <?php ActiveForm::end(); ?>
        </div>
    </div>
</div>
<script>
    function addCard() {
        var nextDiv = '<div class="form-group required">' +
            '<label class="control-label">卡券批次card_id</label>' +
            '<button type="button" class="btn btn-primary" style="margin-left:10px;" onclick="delCard(this)">删除</button>' +
            '<input type="text" class="form-control" name="CardPageForm[card_id][]" placeholder="卡券批次card_id">' +
            '</div>';
        var next2Div = '<div class="form-group required">' +
            '<label class="control-label">卡券缩略图地址</label>' +
            '<input type="text" class="form-control" name="CardPageForm[thumb_url][]" placeholder="卡券缩略图地址">' +
            '</div>';
        $('#submit_form').before(nextDiv);
        $('#submit_form').before(next2Div);
    }
    function delCard(that) {
        var nextDiv = $(that).parent().next();
        $(that).parent().remove();
        nextDiv.remove();
    }
</script>